package com.sunday.common.mq.rocket.brave.study.base.e5_Filter_Message;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
public class FilterMessageProducer {

    public static void main(String[] args) throws Exception {

        // 实例化一个生产者来产生延时消息
        DefaultMQProducer producer = new DefaultMQProducer("filter_producer_group_name");
        // 设置NameServer的地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动生产者
        producer.start();

        for (int i = 0; i < 10; i++) {
            String body = "Hello scheduled message " + i;
            Message message = new Message("filter_topic", body.getBytes());
            // 设置一些属性
            message.putUserProperty("a", String.valueOf(i));
            // 发送消息
            SendResult sendResult = producer.send(message);
            log.info("SendResult status:{}, queueId:{}, body:{}",
                    sendResult.getSendStatus(),
                    sendResult.getMessageQueue().getQueueId(),
                    body);
        }
        // 关闭生产者
        producer.shutdown();
    }

}
